package org.ufinity.hsms.common.activity;

import org.ufinity.hsms.common.application.HSMApplication;
import org.ufinity.hsms.module.setting.SettingActivity;

import android.app.Activity;
import android.app.ActivityGroup;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore.MediaColumns;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.widget.Toast;


/**
 * @Description 实现一些基础方法
 * @author 钱新才
 */

public class BaseActivity extends Activity {

	protected Activity instance;
	protected Context mContext;
	protected final String SDCARD_MNT = "/mnt/sdcard";
	protected final String SDCARD = "/sdcard";

	protected Toast myToast;

	public HSMApplication getBaseApplication() {
		return (HSMApplication) getApplication();
	}
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// 设置账号
		mContext = getApplicationContext();
		HSMApplication application = getBaseApplication();
	}
	
	/**
	 * @param context
	 * @param text
	 */
	protected void makeMyToast(Context context, String text) {
		myToast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
		myToast.setGravity(Gravity.CENTER, 0, 0);
		myToast.show();
	}

	/**
	 * 通过uri获取文件的绝对路径
	 * 
	 * @param uri
	 * @return
	 */
	protected String getAbsoluteImagePath(Uri uri) {
		String imagePath = "";
		String[] proj = { MediaColumns.DATA };
		Cursor cursor = managedQuery(uri, proj, // Which columns to return
				null, // WHERE clause; which rows to return (all rows)
				null, // WHERE clause selection arguments (none)
				null); // Order-by clause (ascending by name)

		if (cursor != null) {
			int column_index = cursor.getColumnIndexOrThrow(MediaColumns.DATA);
			if (cursor.getCount() > 0 && cursor.moveToFirst()) {
				imagePath = cursor.getString(column_index);
			}
		}
		return imagePath;
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		return super.onKeyDown(keyCode, event);
	}
	
	
	
	
}

